package mytest.util;

import javax.servlet.http.HttpServletRequest;
import test.service.ServiceUser;
import test.user.user;

public class RequestUtil {
	
	public static String getUserName(HttpServletRequest request) {
		String token = request.getHeader("token");
		return token.split("\\|")[0];
	}
	
	public static String getProjectId(HttpServletRequest request) {
		return request.getHeader("projectid").toString();
	}
	
	public static String getUserId(HttpServletRequest request) {
		return ServiceUser.getUserByUserName(getUserName(request)).getUserid();
	}
	
	
	public static user getUser(HttpServletRequest request) {
		return ServiceUser.getUser(getUserId(request));
	}
	
	public static int getStartPage(HttpServletRequest request) {
		return (Integer.valueOf(request.getParameter("page"))-1)*Integer.valueOf(request.getParameter("limit"));
	}
	
	public static int getEndPage(HttpServletRequest request) {
		return Integer.valueOf(request.getParameter("limit")) + getStartPage(request);
	}

}
